<script setup>
import { ArrowDown, ArrowUp } from '@element-plus/icons-vue'
import { ref } from 'vue'
// import AssignRole from './components/assignRole.vue'

import tableData from '~mock/user'

// 表单状态
const filterState = ref(true)
// 表单数据
const isExpand = ref(false)
const formData = {
  pagenum: 1,
  pagesize: 10,
  username: '',
  mobile: '',
  role_name: '',
  created_at: '',
  updated_at: '',

  created_at_temp: [], // el-date-picker组件保存是数组
  updated_at_temp: [] // el-date-picker组件保存是数组
}

// 分页
const onSizeChange = (val) => {
  console.log(`${val} items per page`)
}
const onCurrentChange = (val) => {
  console.log(`current page: ${val}`)
}

// 登录编辑
const infoRef = ref()

const userState = ref('')
const userStateOption = [
  {
    value: 1,
    label: '正常'
  },
  {
    value: 0,
    label: '禁用'
  }
]

// 批量选择
let ids = ref([])
const onSelectionChange = (val) => {
  ids.value = val
}
</script>
<template>
  <Box>
    <!-- 逻辑层 -->
    <Info ref="infoRef" />
    <!-- <AssignRole ref="assignRoleRef" /> -->
    <!-- 逻辑层 -->

    <!-- 筛选 -->
    <template #filter v-if="filterState">
      <el-form :inline="true" :model="formData">
        <el-form-item label="登录地址">
          <el-input placeholder="请输入登录地址" v-model="formData.username" />
        </el-form-item>
        <el-form-item label="用户名称">
          <el-input placeholder="请输入用户名称" v-model="formData.mobile" />
        </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="userState" placeholder="登录状态" style="width: 120px">
            <el-option
              v-for="item in userStateOption"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="登录时间" v-show="isExpand">
          <el-date-picker
            v-model="formData.created_at_temp"
            type="datetimerange"
            range-separator="到"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary"> <span class="iconfont icon-sousuo"></span>搜索 </el-button>
          <el-button type="default"> 重置 </el-button>
          <el-button type="primary" link @click="isExpand = !isExpand">
            {{ isExpand ? '收起' : '展开' }}
            <el-icon>
              <ArrowUp v-if="isExpand" />
              <ArrowDown v-else />
            </el-icon>
          </el-button>
        </el-form-item>
      </el-form>
    </template>
    <!-- 筛选 -->
    <!-- 内容 -->
    <!-- 按钮组 -->
    <el-row>
      <el-col :span="12">
        <el-button type="danger" :disabled="!ids.length">
          <span class="iconfont icon-shanchu"></span>删除
        </el-button>
        <el-button type="danger"> <span class="iconfont icon-shanchu"></span>清空 </el-button>
        <el-button type="warning" @click="$message.warning('演示数据，禁止操作')">
          <span class="iconfont icon-xiazai-"></span>导出
        </el-button>
      </el-col>

      <el-col :span="12" style="text-align: right">
        <el-button circle @click="filterState = !filterState">
          <span class="iconfont icon-sousuo"></span>
        </el-button>
        <el-button circle>
          <span class="iconfont icon-shuaxin"></span>
        </el-button>
      </el-col>
    </el-row>
    <!-- 按钮组 -->
    <!-- 表格 -->
    <el-table :data="tableData.data" :border="true" @selection-change="onSelectionChange">
      <el-table-column type="selection" align="center" fixed="left"></el-table-column>
      <el-table-column label="访问编号" prop="id" align="center" width="200"></el-table-column>
      <el-table-column label="用户名称" align="center" width="200">
        <template #default="scope">
          <span>{{ scope.row.account }}</span>
        </template>
      </el-table-column>
      <el-table-column label="登录地址" align="center" width="200">
        <template #default="scope">
          <span>{{ scope.row.nickname }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="所属角色"
        prop="role_name"
        align="center"
        width="200"
      ></el-table-column>
      <el-table-column label="登录地点" prop="mobile" align="center" width="200"></el-table-column>
      <el-table-column label="浏览器" prop="mobile" align="center" width="200"></el-table-column>
      <el-table-column label="操作系统" prop="mobile" align="center" width="200"></el-table-column>
      <el-table-column label="登录状态" align="center" width="200">
        <template #default="scope">
          <el-tag>{{ scope.row.nickname }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="操作信息"
        prop="created_at"
        align="center"
        width="200"
      ></el-table-column>
      <el-table-column
        label="登录日期"
        prop="created_at"
        align="center"
        width="200"
      ></el-table-column>
    </el-table>
    <!-- 表格 -->
    <!-- 分页 -->
    <el-pagination
      v-model:current-page="formData.pagenum"
      v-model:page-size="formData.pagesize"
      :page-sizes="[10, 20, 30, 40]"
      :background="true"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400"
      @size-change="onSizeChange"
      @current-change="onCurrentChange"
    />
    <!-- 分页 -->
    <!-- 内容 -->
  </Box>
</template>
